<?php
class Shopping_Form_Validate_ProductCategory_Edit{
	
	//CHUA NHUNG THONG BAO LOI CUA FORM
	protected $_messagesError = null;
	
	//MANG CHUA DU LIEU SAU KHI KIEM TRA
	protected  $_arrData;
	
	public function __construct($arrParam = array(), $options = null){
		
		//=========================================
		//KIEM TRA NAME
		//==========================================
		
		$clause = 'id != '. $arrParam['id'];
		$option    = array('table'=>'product_category',
							'field'=>'name',
							'exclude'=>$clause
							);
		$validator = new Zend_Validate();
		$validator->addValidator(new Zendvn_Validate_NotEmpty(),true)
				  ->addValidator(new Zendvn_Validate_StringLength(1,200),true)
				  ->addValidator(new Zendvn_Validate_Db_NoRecordExists($option),true);
		if(!$validator->isValid($arrParam['name'])){
			$message = $validator->getMessages();
			$this->_messagesError['name'] = 'Tên: '.current($message);
			$arrParam['name']='';
		}
		
		
		//=========================================
		//KIEM TRA  ORDER
		//==========================================
		$validator = new Zend_Validate();
		$validator->addValidator(new Zendvn_Validate_NotEmpty(),true)
				  ->addValidator(new Zendvn_Validate_Int(),true);
		if(!$validator->isValid($arrParam['order'])){
			$message = $validator->getMessages();
			$this->_messagesError['order'] = 'Giá trị: '.current($message);
			$arrParam['order']='';
		}
	
		//=========================================
		//TRUYEN CAC GIA TRI DUNG VAO $_arrData
		//==========================================
		$this->_arrData = $arrParam;
	}
	
	//KIEM TRA LOI
	//return true neu co loi xay ra
	public function isError(){
		if(count($this->_messagesError)>0){
			return true;
		}else{
			return false;
		}
		
	}
	
	//TRA VE MOT MANG CAC LOI
	public function getMessageError(){
		return $this->_messagesError;
	}
		
	//TRA VE MOT MANG DU LIEU SAU KHI KIEM TRA
	public function getData($options = null){
	 	return $this->_arrData;
	}
}